package com.zdb.demo.design.pattern.behavioral.observer;

import java.util.Observable;
import java.util.Observer;

public class Demo {

    public static void main(String[] args) {
        Observer observer = new Observer() {
            @Override
            public void update(Observable o, Object arg) {
                System.out.println(((Subject)o).getName());
            }
        };

        Subject subject = new Subject();
        subject.addObserver(observer);

        subject.setName("hello");
        subject.notifyObservers();

    }
}

class Subject extends Observable {

    String name;

    public void setName(String name) {
        this.name = name;
        setChanged();
    }

    public String getName() {
        return name;
    }
}
